reverse a string in javascript using loops